package edu.ucsd.ccdb.util;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

public class RefreshTreeActionListener implements ActionListener {

	JTree tree;
	DefaultMutableTreeNode root;
	
	public RefreshTreeActionListener (JTree tree, DefaultMutableTreeNode root) {
		this.tree = tree;
		this.root= root;
	}
	
	public void actionPerformed(ActionEvent e) {
		
		root.removeAllChildren();
		
		try {
			TreeOperation.createNodes (root);
		} catch (NullPointerException e1) {
			
			e1.printStackTrace();
		} catch (IOException e1) {
			
			e1.printStackTrace();
		}
		
		// reload the tree 
		DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
		model.reload();
	}	

	
}
